package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class MyAdvice {

    public void before(JoinPoint jp) {
        //通过JoinPoint参数获取调用原始方法携带的参数
        System.out.println("before ...");
        Object[] args = jp.getArgs();
        for (Object arg : args) {
            System.out.println(arg);
        }
    }

    public void before1(int x, int y) {
        System.out.println("before(int) " + x + ", " + y);
    }

    public void after() {
        System.out.println("after ...");
    }

    public Object arround(ProceedingJoinPoint pjp) {
        System.out.println("环绕前...");
        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable throwable) {
            System.out.println("aroundException is " + throwable.getMessage());
        }
        System.out.println("环绕后..."+result);
        return result;
    }

    public void afterReturning(Object obj) {
        System.out.println("afterReturning is run ..." + obj);
    }

    public void afterThrowing(Throwable e) {
        System.out.println("afterThrowing is run ..." + e.getMessage());
    }
}
